package br.com.lumis.ims.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import br.com.lumis.ims.model.Balanceador;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancing;
import com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingClient;
import com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult;
import com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription;

public class ELBService {
	
	public List<Balanceador> getBalanceadores(AWSCredentials credentials) {
		AmazonElasticLoadBalancing elb = new AmazonElasticLoadBalancingClient(credentials);
		
		DescribeLoadBalancersResult resultado = elb.describeLoadBalancers();
		
		List<Balanceador> retorno = new ArrayList<Balanceador>();
		
		Iterator<LoadBalancerDescription> itElbs = resultado.getLoadBalancerDescriptions().iterator();
		while(itElbs.hasNext()) {
			LoadBalancerDescription lbDesc = itElbs.next();
			Balanceador balanceador = new Balanceador();
			
			balanceador.setNome(lbDesc.getLoadBalancerName());
			
			retorno.add(balanceador);
		}
		
		return retorno;
	}

}
